package day01.file;

import java.io.File;

/**
 * @ClassName Test3
 * @Description TODO
 * @Author 16433
 * @Date 2023/3/14 16:07
 * @Version 1.0
 *
 * 获取file文件中大小超过1000字节的所有子项
 * 输出这些子项的名字和实际占用的字节数
 **/
public class Test3 {
    public static void main(String[] args) {
        /*//文件过滤器
        FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.length()>1000;
            }
        };
        //获取所有的子项
        File dir = new File("./JSD2205_SE/src/day01/file");
        if(dir.isDirectory()){
            File[] subs = dir.listFiles(filter);
            for (int i = 0; i < subs.length; i++) {
                System.out.println(subs[i].getName()+":"+subs[i].length());
            }
        }*/
        /*//以上代码的简写方式
        File dir = new File("./JSD2205_SE/src/day01/file");
        if(dir.isDirectory()){
            File[] subs = dir.listFiles(new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.length()>1000;
                }
            });
            for (int i = 0; i < subs.length; i++) {
                System.out.println(subs[i].getName()+":"+subs[i].length());
            }
        }*/
        //Lambda表达式的方式
        File dir = new File("./JSD2205_SE/src/day01/file");
        if(dir.isDirectory()){
            File[] subs = dir.listFiles(pathname -> pathname.length()>1000);
            for (int i = 0; i < subs.length; i++) {
                System.out.println(subs[i].getName()+":"+subs[i].length());
            }
        }
    }
}
